package leetcode.editor.cn.q0xx

class Q38 {
    fun countAndSay(n: Int): String {
        if (n==1) return "1"

        return desc(countAndSay(n-1))
    }

    fun desc(say: String): String {
        var count = 1
        var cur = say[0]
        var result = ""
        for (c in say.substring(1)) {
            if (c == cur) {
                count++
            } else {
                result += count
                result += cur
                cur = c
                count = 1
            }
        }
        result += count
        result += cur
        return result
    }
}